package com.rich.group.controller;

import com.rich.common.annotation.IngoreResponseAdvice;
import com.rich.common.constant.GroupBuyEnum;
import com.rich.common.constant.MyGlobalConstant;
import com.rich.group.pojo.GroupBuy;
import com.rich.group.service.GroupBuyService;
import com.rich.group.vo.GroupBuySearchVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author minicoco
 * @version 1.0
 * @date 2021/8/16 10:36
 */
@RestController
@RequestMapping("/group/buy")
public class GroupBuyController {

    @Autowired
    private GroupBuyService groupBuyService;

    /**
     * 添加拼团活动
     */
    @PostMapping("/addGroupBuy")
    public void addGroupBuy(@RequestBody GroupBuy groupBuy){
        groupBuyService.addGroupBuy(groupBuy);
    }

    /**
     * 添加拼团活动到redis
     */
    @GetMapping("/saveCache")
    public void saveCache(){
        groupBuyService.saveCache();
    }

    /**
     * 查询单条
     * @param id
     * @return
     */
    @GetMapping("/fineOneById/{id}")
    public GroupBuy fineOneById(@PathVariable("id") Long id){
        return groupBuyService.fineOneById(id);
    }

    /**
     * 修改状态
     */
    @PutMapping("/updateStatus/{id}/{status}")
    public void updateStatus(@PathVariable("id") Long id ,@PathVariable("status") String status){
        groupBuyService.updateStatus(id,status);
    }

    /**
     *开团
     */
    @PutMapping("/startGroup")
    public void startGroup(@RequestBody GroupBuy groupBuy){
        groupBuyService.startGroup(groupBuy);
    }

    /**
     * 删除
     */
    @DeleteMapping("/removeGroupBuy/{id}")
    public void removeGroupBuy(@PathVariable("id") Long id){
        groupBuyService.removeGroupBuy(id);
    }

    /**
     * 经纪人端查询拼团信息
     */
    @GetMapping("/getBrokerList")
    public List<GroupBuy> getBrokerList(){
        return groupBuyService.getBrokerList();
    }

    /**
     * 客户端列表
     */
    @GetMapping("/getUserList")
    public List<GroupBuy> getUserList(){
        return groupBuyService.getUserList();
    }

    /**
     * 后台管理列表
     */
    @PostMapping("/getBackgroundList")
    public List<GroupBuy> getBackgroundList(@RequestBody GroupBuySearchVo groupBuySearchVo){
        return groupBuyService.getBackgroundList(groupBuySearchVo);
    }


}
